home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / sharewar / FFE / GRAPH.SWG / 0068_Impulse's Turbo Silver 3.0 3D (TDDD).pas < prev    next >
Pascal/Delphi Source File  |  1997-05-12  |  24KB  |  551 lines

  1. Here is the description of the Turbo Silver TDDD chunk. If you order the
  2. 'File  formats  diskette' (value $5) from  Impulse Inc. you also get the
  3. source  for a program to read/write an object file. As I'm not sure that
  4. the program is Public Domain, I'll not post the program.
  5.  
  6. ======================================================================
  7.  
  8.                           FORM TDDD
  9.                           ---------
  10.  
  11.     FORM TDDD is used by Impulse's Turbo Silver 3.0 for 3D rendering
  12.     data.  TDDD stands for "3D data description".  The files contain
  13.     object and (optionally) observer data.
  14.  
  15.     Currently, in "standard IFF" terms, a FORM TDDD has only two chunk
  16.     types:  an INFO chunk describing observer data;  and an OBJ chunk
  17.     describing an object heirarchy.  The INFO chunk appears in "cell"
  18.     files, and the OBJ chunk appears in "cell" files and "object" files.
  19.     The FORM has an (optional) INFO chunk followed by some number of
  20.     OBJ chunks.  (Note:  OBJ is followed by a space -- ckID = "OBJ ")
  21.  
  22.     The INFO and OBJ chunks, in turn, are made up of smaller chunks with
  23.     the standard IFF structure:  <ID> <data-size> <data>.
  24.  
  25.     The INFO "sub-chunks" are relatively straightforward to interpret.
  26.  
  27.     The OBJ "sub-chunks" support object heirarchies, and are slightly
  28.     more difficult to interpret.  Currently, there are 3 types of OBJ
  29.     sub-chunks:  an EXTR chunk, describing an "external" object in a
  30.     seperate file; a DESC chunk, describing one node of a heirarchy;
  31.     and a TOBJ chunk marking the end of a heirarchy chain.  For each
  32.     DESC chunk, there must be a corresponding TOBJ chunk.  And an
  33.     EXTR chunk is equivalent to a DESC/TOBJ pair.
  34.  
  35.     In Turbo Silver, the structure of the object heirarchy is as
  36.     follows.  There is a head object, and its (sexist) brothers.
  37.     Each brother may have child objects.  The children may have
  38.     grandchildren, and so on. The brother nodes are kept in a
  39.     doubly linked list, and each node has a (possibly NULL)
  40.     pointer to a doubly linked "child" list. The children point
  41.     to the "grandchildren" lists, and so on.  (In addition, each
  42.     node has a "back" pointer to its parent).
  43.  
  44.     Each of the "head" brothers is written in a seperate OBJ chunk,
  45.     along with all its descendants.  The descendant heirarchy is
  46.     supported as follows:
  47.  
  48.         for each node of a doubly linked list,
  49.  
  50.         1)  A DESC chunk is written, describing its object.
  51.         2)  If it has children, steps 1) to 3) are performed
  52.             for each child.
  53.         3)  A TOBJ chunk is written, marking the end of the children.
  54.  
  55.     For "external" objects, steps 1) to 3) are not performed, but
  56.     an EXTR chunk is written instead.  (This means that an external
  57.     object cannot have children unless they are stored in the same
  58.     "external" file).
  59.  
  60.     The TOBJ sub-chunks have zero size -- and no data.  The DESC
  61.     and EXTR sub-chunks are made up of "sub-sub-chunks", again,
  62.     with the standard IFF structure:  <ID> <data-size> <data>.
  63.  
  64.     Reader software WILL FOLLOW the standard IFF procedure of
  65.     skipping over any un-recognized chunks -- and "sub-chunks"
  66.     or "sub-sub-chunks". The <data-size> field indicates how many
  67.     bytes to skip.  In addition it WILL OBSERVE the IFF rule that
  68.     an odd <data-size> may appear, in which case the corredponding
  69.     <data> field will be padded at the end with one extra byte to
  70.     give it an even size.
  71.  
  72.  
  73.     Now, on with the details.
  74.  
  75.     First, there are several numerical fields appearing in the data,
  76.     describing object positions, rotation angles, scaling factors, etc.
  77.     They are stored as "32-bit fractional" numbers, such that the true
  78.     number is the 32-bit number divided by 65536.  So as an example,
  79.     the number 3.14159 is stored as (hexadecimal) $0003243F.  This
  80.     allows the data to be independant of any particular floating point
  81.     format. And it (actually) is the internal format used in the
  82.     "integer" version of Turbo Silver.  Numbers stored in this format
  83.     are called as "FRACT"s below.
  84.  
  85.     Second, there are several color (or RGB) fields in the data.
  86.     They are always stored as three UBYTEs representing the red,
  87.     green and blue components of the color.  Red is always first,
  88.     followed by green, and then blue.  For some of the data chunks,
  89.     Turbo Silver reads the color field into the 24 LSB's of a
  90.     LONGword.  In such cases, the 3 RGB bytes are preceded by a
  91.     zero byte in the file.
  92.  
  93.  
  94.     The following "typedef"s are used below:
  95.  
  96.     typedef LONG    FRACT;          /* 4 bytes */
  97.     typedef UBYTE   COLOR[3];       /* 3 bytes */
  98.  
  99.     typedef struct  vectors {
  100.         FRACT   X;                  /* 4 bytes */
  101.         FRACT   Y;                  /* 4 bytes */
  102.         FRACT   Z;                  /* 4 bytes */
  103.     } VECTOR;                   /* 12 bytes total */
  104.  
  105.     typedef struct  matrices {
  106.         VECTOR  I;                  /* 12 bytes */
  107.         VECTOR  J;                  /* 12 bytes */
  108.         VECTOR  K;                  /* 12 bytes */
  109.     } MATRIX;                   /* 36 bytes total */
  110.  
  111.  
  112.     The following structure is used in generating animated cells
  113.     from a single cell.  It can be attached to an object or to the
  114.     camera.  It is also used for Turbo Silver's "extrude along a
  115.     path" feature.
  116.  
  117.     typedef struct  story   {
  118.         UBYTE   Path[18];           /*  18 bytes        */
  119.         VECTOR  Translate;          /*  12 bytes        */
  120.         VECTOR  Rotate;             /*  12 bytes        */
  121.         VECTOR  Scale;              /*  12 bytes        */
  122.         UWORD   info;               /*   2 bytes        */
  123.     } STORY;                    /*  56 bytes total  */
  124.  
  125.     The Path[] name refers to a named object in the cell data.
  126.     The path object should be a sequence of points connected
  127.     with edges.  The object moves from the first point of the
  128.     first edge, to the last point of the last edge.  The edge
  129.     ordering is important.  The path is interpolated so that
  130.     the object always moves an equal distance in each frame of
  131.     the animation.  If there is no path the Path[] field should
  132.     be set to zeros.
  133.     The Translate vector is not currently used.
  134.     The Rotate "vector" specifies rotation angles about the
  135.     X, Y, and Z axes.
  136.     The Scale vector specfies X,Y, and Z scale factors.
  137.     The "info" word is a bunch of bit flags:
  138.  
  139.         ABS_TRA     0x0001      - translate in world coorinates (not used)
  140.         ABS_ROT     0x0002      - rotation in world coorinates
  141.         ABS_SCL     0x0004      - scaling in world coorinates
  142.         LOC_TRA     0x0010      - translate in local coorinates (not used)
  143.         LOC_ROT     0x0020      - rotation in local coorinates
  144.         LOC_SCL     0x0040      - scaling in local coorinates
  145.         X_ALIGN     0x0100      - (not used)
  146.         Y_ALIGN     0x0200      - align Y axis to path's direction
  147.         Z_ALIGN     0x0400      - (not used)
  148.         FOLLOW_ME   0x1000      - children follow parent on path
  149.  
  150.  
  151.     INFO sub-chunks
  152.     ---------------
  153.  
  154.     BRSH - size 82
  155.  
  156.         WORD    Number;                 ; Brush number (between 0 and 7)
  157.         CHAR    Filename[80];           ; IFF ILBM filename
  158.  
  159.         There may be more than one of these.
  160.  
  161.     STNC - size 82
  162.  
  163.         Same format as BRSH chunk.
  164.  
  165.     TXTR - size 82
  166.  
  167.         Same format as BRSH chunk.  The Filename field is the name of
  168.         a code module that can be loaded with LoadSeg().
  169.  
  170.     OBSV - size 28
  171.  
  172.         VECTOR  Camera;                 ; Camera position
  173.         VECTOR  Rotate;                 ; Camera rotation angles
  174.         FRACT   Focal;                  ; Camera focal length
  175.  
  176.         This tells where the camera is, how it is aimed, and its
  177.         focal length.  The rotation angles are in degrees, and specify
  178.         rotations around the X, Y, and Z axes.  The camera looks down
  179.         its own Y axis, with the top of the picture in the direction of
  180.         the Z axis.  If the rotation angles are all zero, its axes
  181.         are aligned with the world coordinate axes.  The rotations are
  182.         performed in the order ZXY about the camera axes.  A positive
  183.         angle rotates Y toward Z, Z toward X, and X toward Y for
  184.         rotations about the X, Y, and Z axes respectively.  To
  185.         understand the focal length, imagine a 320 x 200 pixel
  186.         rectangle perpendicular to, and centered on the camera's
  187.         Y axis.  Any objects in the infinite rectangular cone defined
  188.         by the camera position and the 4 corners of the rectangle will
  189.         appear in the picture.
  190.  
  191.     OTRK - size 18
  192.  
  193.         BYTE    Trackname[18];
  194.  
  195.         This chunk specifies the name of an object that the camera
  196.         is "tracked" to.  If the name is NULL, the camera doesn't
  197.         track.  Otherwise, if the object is moved inside Turbo Silver,
  198.         the camera will follow it.
  199.  
  200.     OSTR - size 56
  201.  
  202.         STORY   CStory;         ; a STORY structure for the camera
  203.  
  204.         The story structure is defined above.
  205.  
  206.     FADE - size 12
  207.  
  208.         FRACT   FadeAt;         ; distance to start fade
  209.         FRACT   FadeBy;         ; distance of total fade
  210.         BYTE    pad;            ; pad byte - must be zero
  211.         COLOR   FadeTo;         ; RGB color to fade to
  212.  
  213.     SKYC - size 8
  214.  
  215.         BYTE    pad;            ; pad byte - must be zero
  216.         COLOR   Horizon;        ; horizon color
  217.         BYTE    pad;            ; pad byte - must be zero
  218.         COLOR   Zenith;         ; zenith color
  219.  
  220.     AMBI - size 4
  221.  
  222.         BYTE    pad;            ; pad byte - must be zero
  223.         COLOR   Ambient;        ; abmient light color
  224.  
  225.     GLB0 - size 8
  226.  
  227.         BYTE    Props[8];       ; an array of 8 "global properties" used
  228.                                 ; by Turbo Silver.
  229.  
  230.         Props[0] - GLB_EDGING       ; edge level (globals requester)
  231.         Props[1] - GLB_PERTURB      ; perturbance (globals requester)
  232.         Props[2] - GLB_SKY_BLEND    ; sky blending factor (0-255)
  233.         Props[3] - GLB_LENS         ; lens type (see below)
  234.         Props[4] - GLB_FADE         ; flag - Sharp/Fuzzy focus (globals)
  235.         Props[5] - GLB_SIZE         ; "apparant size" (see below)
  236.         Props[6] - GLB_RESOLVE      ; resolve depth (globals requester)
  237.         Props[7] - GLB_EXTRA        ; flag - genlock sky on/off
  238.  
  239.         The edging and perturbance values control the heuristics in
  240.         ray tracing.  The sky blending factor is zero for no blending,
  241.         and 255 for full blending.  The lens type is a number from 0
  242.         4, corresponding to the boxes in the "camera" requester, and
  243.         correspond to 0) Manual, 1) Wide angle, 2) Normal, 3) Telephoto,
  244.         and 4) Custom.  It is used in setting the camera's focal length
  245.         if the camera is tracked to an object.  The Sharp/Fuzzy flag
  246.         turns the "fade" feature on and off - non-zero means on.
  247.         The "apparant size" parameter is 100 times the "custom size"
  248.         parameter in the camera requester.  And is used to set the
  249.         focal length for a custom lens.  The "resolve depth" controls
  250.         the number of rays the ray tracer will shoot for a single pixel.
  251.         Each reflective/refractive ray increments the depth counter, and
  252.         the count is never allowed to reach the "resolve depth".  If both
  253.         a reflective and a refractive ray are traced, each ray gets its
  254.         own version of the count - so theoretically, a resolve depth of
  255.         4 could allow much more than 4 rays to be traced.  The "genlock
  256.         sky" flag controls whether the sky will be colored, or set to
  257.         the genlock color (color 0 - black) in the final picture.
  258.  
  259.  
  260.     All of the INFO sub-chunks are optional, as is the INFO chunk.
  261.     Default values are supplied if the chunks are not present.  The
  262.     defaults are:  no brushes, stencils, or textures defined; no story
  263.     for the camera; horizon and zenith and ambient light colors set
  264.     to black; fade color set to (80,80,80);  un-rotated, un-tracked
  265.     camera at (-100, -100, 100); and global properties array set to
  266.     [30, 0, 0, 0, 0, 100, 8, 0].
  267.  
  268.  
  269.     DESC sub-sub-chunks
  270.     -------------------
  271.  
  272.     NAME - size 18
  273.  
  274.         BYTE    Name[18];       ; a name for the object.
  275.  
  276.         Used for camera tracking, specifying story paths, etc.
  277.  
  278.     SHAP - size 4
  279.  
  280.         WORD    Shape;          ; number indicating object type
  281.         WORD    Lamp;           ; number indicating lamp type
  282.  
  283.         Lamp numbers are:
  284.  
  285.             0 - not a lamp
  286.             1 - like sunlight
  287.             2 - like a lamp - intensity falls off with distance.
  288.  
  289.         Shape numbers are:
  290.  
  291.             0 - Sphere
  292.             1 - Stencil
  293.             2 - Axis            ; custom objects with points/triangles
  294.             3 - Facets          ; illegal - for internal use only
  295.             4 - Surface
  296.             5 - Ground
  297.  
  298.         Spheres have thier radius set by the X size parameter.
  299.         Stencils and surfaces are plane-parallelograms, with one
  300.         point at the object's position vector; one side lying along
  301.         the object's X axis with a length set by the X size; and
  302.         another side starting from the position vector and going
  303.         "Y size" units in the Y direction and "Z size" units in
  304.         the X direction.  A ground object is an infinte plane
  305.         perpendicular to the world Z axis.  Its Z coordinate sets
  306.         its height, and the X and Y coordinates are only relevant
  307.         to the position of the "hot point" used in selecting the
  308.         object in the editor.  Custom objects have points, edges
  309.         and triangles associated with them.  The size fields are
  310.         relevant only for drawing the object axes in the editor.
  311.         Shape number 3 is used internally for triangles of custom
  312.         objects, and should never appear in a data file.
  313.  
  314.     POSI - size 12
  315.  
  316.         VECTOR  Position;       ; the object's position.
  317.  
  318.         Legal coordinates are in the range -32768 to 32767 and 65535/65536.
  319.         Currently, the ray-tracer only sees objects in the -1024 to 1024
  320.         range.  Light sources, and the camera may be placed outside that
  321.         range, however.
  322.  
  323.     AXIS - size 36
  324.  
  325.         VECTOR  XAxis;
  326.         VECTOR  YAxis;
  327.         VECTOR  ZAxis;
  328.  
  329.         These are direction vectors for the object coordinate system.
  330.         They must be "orthogonal unit vectors" - i.e. the sum of the
  331.         squares of the vevtor components must equal one (or close to it),
  332.         and the vectors must be perpendicular.
  333.  
  334.     SIZE - size 12
  335.  
  336.         VECTOR  Size;
  337.  
  338.         See SHAP chunk above.  The sizes are used in a variety of ways
  339.         depending on the object shape.  For custom objects, they are
  340.         the lengths of the coordinate axes drawn in the editor.  If the
  341.         object has its "Quickdraw" flag set, the axes lengths are also
  342.         used to set the size of a rectangular solid that is drawn rather
  343.         than drawing all the points and edges.
  344.  
  345.     PNTS - size 2 + 12 * point count
  346.  
  347.         UWORD   PCount;         ; point count
  348.         VECTOR  Points[];       ; points
  349.  
  350.         This chunk has all the points for custom objects.  The are
  351.         refered to by thier position in the array.
  352.  
  353.     EDGE - size 4 + 4 * edge cout
  354.  
  355.         UWORD   ECount;         ; edge count
  356.         UWORD   Edges[][2];     ; edges
  357.  
  358.         This chunk contins the edge list for custom objects.
  359.         The Edges[][2] array is pairs of point numbers that
  360.         are connected by the edges.  Edges are refered to by thier
  361.         position in the Edges[] array.
  362.  
  363.     FACE - size 2 + 6 * face count
  364.  
  365.         UWORD   TCount;         ; face count
  366.         UWORD   Connects[][3];  ; faces
  367.  
  368.         This chunk contains the triangle (face) list for custom objects.
  369.         The Connects[][3] array is triples of edge numbers that are
  370.         connected by triangles.
  371.  
  372.     COLR - size 4
  373.     REFL - size 4
  374.     TRAN - size 4
  375.  
  376.         BYTE    pad;        ; pad byte - must be zero
  377.         COLOR   col;        ; RGB color
  378.  
  379.         These are the main object RGB color, and reflection and
  380.         transmission coefficients.
  381.  
  382.     CLST - size 2 + 3 * count
  383.     RLST - size 2 + 3 * count
  384.     TLST - size 2 + 3 * count
  385.  
  386.         UWORD   count;      ; count of colors
  387.         COLOR   colors[];   ; colors
  388.  
  389.         These are the main object color, and reflection and
  390.         transmission coefficients for each face in custom objects.
  391.         The count should match the face count in the FACE chunk.
  392.         The ordering corresponds to the face order.
  393.  
  394.     TPAR - size 64
  395.  
  396.         FRACT   Params[16];     ; texture parameters
  397.  
  398.         This is the list of parameters for texture modules when
  399.         texture mapping is used.
  400.  
  401.     SURF - size 5
  402.  
  403.         BYTE    SProps[5];      ; object properties
  404.  
  405.         This chunk contains object (surface) properties used
  406.         by Turbo Silver.
  407.  
  408.         SProps[0] - PRP_SURFACE     ; surface type
  409.                                     ;   0 - normal
  410.                                     ;   4 - genlock
  411.                                     ;   5 - IFF brush
  412.         SProps[1] - PRP_BRUSH       ; brush number (if IFF mapped)
  413.         SProps[2] - PRP_WRAP            ; IFF brush wrapping type
  414.                                     ;   0 - no wrapping
  415.                                     ;   1 - wrap X
  416.                                     ;   2 - wrap Z
  417.                                     ;   3 - wrap X and Z
  418.         SProps[3] - PRP_STENCIL     ; stencil number for stencil objects
  419.         SProps[4] - PRP_TEXTURE     ; texture number if texture mapped
  420.  
  421.     MTTR - size 2
  422.  
  423.         UBYTE   Type;               ; refraction type (0-4)
  424.         UBYTE   Index;              ; custom index of refraction
  425.  
  426.         This chunk contains refraction data for transparent or
  427.         glossy objects.  If the refraction type is 4, the object
  428.         has a "custom" refractive index stored in the Index field.
  429.         The Index field is 100 * (true index of refraction - 1.00)
  430.         -- so it must be in the range of 1.00 to 3.55.  The
  431.         refraction types is 0-3 specify 0) Air - 1.00, 1) Water - 1.33,
  432.         2) Glass - 1.67 or 3) Crystal 2.00.
  433.  
  434.     SPEC - size 2
  435.  
  436.         UBYTE   Specularity;            ; range of 0-255
  437.         UBYTE   Hardness;               ; specular exponent (0-31)
  438.  
  439.         This chunk contains specular information.  The Specularity
  440.         field is the amount of specular reflection -- 0 is none,
  441.         255 is fully specular.  The "specular exponent" controls
  442.         the "tightness" of the specular spots.  A value of zero
  443.         gives broad specular spots and a value of 31 gives smaller
  444.         spots.
  445.  
  446.     PRP0 - size 6
  447.  
  448.         UBYTE   Props[6];           ; more object properties
  449.  
  450.         This chunk contains object properties that programs other
  451.         than Turbo Silver might support.
  452.  
  453.         Props[0] - PRP_BLEND        ; blending factor (0-255)
  454.         Props[1] - PRP_SMOOTH       ; roughness factor
  455.         Props[2] - PRP_SHADE        ; shading on/off flag
  456.         Props[3] - PRP_PHONG        ; phong shading on/off flag
  457.         Props[4] - PRP_GLOSSY       ; glossy on/off flag
  458.         Props[5] - PRP_QUICK        ; Quickdraw on/off flag
  459.  
  460.         The blending factor controls the amount of dithering used
  461.         on the object - 255 is fully dithered.
  462.         The roughness factor controls how rough the object should
  463.         appear - 0 is smooth, 255 is max roughness.
  464.         The shading flag is interpreted differently depending on
  465.         whether the object is a light source or not.  For light
  466.         sources, it sets the light to cast shadows or not.  For
  467.         normal objects, if the flag is set, the object is always
  468.         considered as fully lit - i.e. it's color is read directly
  469.         from the object (or IFF brush), and is not affected by light
  470.         sources.
  471.         The phong shading is on by default - a non-zero value turns
  472.         it off.
  473.         The glossy flag sets the object to be glossy or not.  If
  474.         the object is glossy, the "transmit" colors and the index
  475.         of refraction control the amount of "sheen".  The glossy
  476.         feature is meant to simulate something like a wax coating
  477.         on the object with the specified index of refraction. The
  478.         trasmission coefficients control how much light from the
  479.         object makes it through the wax coating.
  480.         The Quickdraw flag, if set, tells the editor not to draw
  481.         all the points and edges for the object, but to draw a
  482.         rectanglular solid centered at the object position, and
  483.         with sizes detemined by the axis lengths.
  484.  
  485.     INTS - size 4
  486.  
  487.         FRACT   Intensity;          ; light intensity
  488.  
  489.         This is the intensity field for light source objects.
  490.         an intensity of 255 for a sun-like light fully lights
  491.         object surfaces which are perpendicular to the direction
  492.         to the light source.  For lamp-like light sources, the
  493.         necessary intensity will depend on the distance to the light.
  494.  
  495.     STRY - size 56
  496.  
  497.         STORY   story;          ; a story structure for the object.
  498.  
  499.         The story structure is described above.
  500.  
  501.  
  502.     Again, most of these fields are optional, and defaults are supplied.
  503.     However, if there is a FACE chunk, there must also be a CLST chunk,
  504.     an RLST chunk and a TLST chunk -- all with matching "count" fields.
  505.     The SHAP chunk is not optional.
  506.  
  507.     Defaults are:  Colors set to (240,240,240); reflection and
  508.     transmission coefficients set to zero; illegal shape; no story or
  509.     special surface types; position at (0,0,0); axes aligned to the
  510.     world axes; size fields all 32.0; intensity at 300; no name;
  511.     no points/edges or faces; texture parameters set to zero; refraction
  512.     type 0 with index 1.00; specular, hardness and roughness set to zero;
  513.     blending at 255; glossy off; phong shading on; not a light source;
  514.     not brightly lit;
  515.  
  516.  
  517.  
  518.     EXTR sub-sub-chunks
  519.     -------------------
  520.  
  521.     MTRX - size 60
  522.  
  523.         VECTOR  Translate;          ; translation vector
  524.         VECTOR  Scale;              ; X,Y and Z scaling factors
  525.         MATRIX  Rotate;             ; rotation matrix
  526.  
  527.         The translation vector is i world coordinates.
  528.         The scaling factors are with respect to local axes.
  529.         The rotation matrix is with respect to the world axes,
  530.         and it should be a "unit matrix".
  531.         The rotation is such that a rotated axis's X,Y, and Z
  532.         components are the dot products of the MATRIX's I,J,
  533.         and K vectors with the un-rotated axis vector.
  534.  
  535.     LOAD - size 80
  536.  
  537.         BYTE    Filename[80];       ; the name of the external file
  538.  
  539.         This chunk contains the name of an external object file.
  540.         The external file should be a FORM TDDD file.  It may contain
  541.         an any number of objects possibly grouped into heirarchy(ies).
  542.  
  543.     Both of these chunks are required.
  544.  
  545. -----
  546. Helge E. Rasmussen  .  PHONE + 45 31 37 11 00  .  E-mail:  her@compel.dk
  547. Compel A/S          .  FAX   + 45 31 37 06 44  .
  548. Copenhagen, Denmark
  549.  
  550.  
  551.